<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>$(NetCoreAppToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
    <IsPackable>true</IsPackable>
    <IsShipping>false</IsShipping>
    <SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
    <PackageDescription>Provides runtime information required to resolve target framework, platform, and runtime specific implementations of .NET packages.</PackageDescription>
    <NoWarn>$(NoWarn);NU5128</NoWarn> <!-- No Dependencies-->

    <!-- Opt out of features that aren't necessary for a local build task. -->
    <EnableBinPlacing>false</EnableBinPlacing>
    <!-- This project should not build against the live built .NETCoreApp targeting pack as it contributes to the build itself. -->
    <UseLocalTargetingRuntimePack>false</UseLocalTargetingRuntimePack>
    <IncludeBuildOutput>false</IncludeBuildOutput>
    <IncludeSymbols>false</IncludeSymbols>

    <_generateRuntimeGraphTargetFramework Condition="'$(MSBuildRuntimeType)' == 'core'">$(NetCoreAppToolCurrent)</_generateRuntimeGraphTargetFramework>
    <_generateRuntimeGraphTargetFramework Condition="'$(MSBuildRuntimeType)' != 'core'">$(NetFrameworkToolCurrent)</_generateRuntimeGraphTargetFramework>
    <_generateRuntimeGraphTask>$([MSBuild]::NormalizePath('$(BaseOutputPath)', $(Configuration), '$(_generateRuntimeGraphTargetFramework)', '$(AssemblyName).dll'))</_generateRuntimeGraphTask>
  </PropertyGroup>

  <ItemGroup>
    <AdditionalRuntimeIdentifiers Include="$(AdditionalRuntimeIdentifiers)" Imports="$(AdditionalRuntimeIdentifierParent)" />
    <!-- When building from source, ensure the RID we're building for is part of the RID graph. -->
    <AdditionalRuntimeIdentifiers Include="$(OutputRID)" Imports="$(AdditionalRuntimeIdentifierParent)" Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
  </ItemGroup>

  <ItemGroup>
    <Compile Include="UpdateRuntimeIdentifierGraph.cs" />
  </ItemGroup>

  <ItemGroup Condition="'@(AdditionalRuntimeIdentifiers)' == ''">
    <Content Include="runtime.json" PackagePath="/" />
    <Content Include="PortableRuntimeIdentifierGraph.json" PackagePath="/" />
  </ItemGroup>

  <ItemGroup Condition="'@(AdditionalRuntimeIdentifiers)' != ''">
    <Content Include="$(BaseOutputPath)runtime.json" PackagePath="/" />
    <Content Include="$(BaseOutputPath)PortableRuntimeIdentifierGraph.json" PackagePath="/" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
    <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
  </ItemGroup>
  
  <UsingTask TaskName="UpdateRuntimeIdentifierGraph" AssemblyFile="$(_generateRuntimeGraphTask)"/>
  <Target Name="UpdateRuntimeIdentifierGraph"
          AfterTargets="Build"
          Condition="'@(AdditionalRuntimeIdentifiers)' != ''">
    <!-- non portable RID graph -->
    <UpdateRuntimeIdentifierGraph InputFile="runtime.json"
                                  OutputFile="$(BaseOutputPath)runtime.json"
                                  AdditionalRuntimeIdentifiers="@(AdditionalRuntimeIdentifiers)" />

    <!-- portable RID graph -->
    <UpdateRuntimeIdentifierGraph InputFile="PortableRuntimeIdentifierGraph.json"
                                  OutputFile="$(BaseOutputPath)PortableRuntimeIdentifierGraph.json"
                                  AdditionalRuntimeIdentifiers="@(AdditionalRuntimeIdentifiers)" />
  </Target>

</Project>
